package cn.itcast.star.graph.core.controller;

import cn.itcast.star.graph.core.pojo.dto.common.Result;
import cn.itcast.star.graph.core.pojo.dto.request.UserLoginReqDTO;
import cn.itcast.star.graph.core.pojo.dto.respone.UserLoginResDTO;
import cn.itcast.star.graph.core.service.UserService;
import org.apache.coyote.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Windows
 */
@RestController
@RequestMapping("/api/1.0/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result<UserLoginResDTO> login(@RequestBody UserLoginReqDTO user) {
        try {
            return Result.ok(userService.loginByPassword(user));
        } catch (BadRequestException e) {
            // 工作中不可以这样处理
            throw new RuntimeException(e);
        }
    }
}